/**
 * Copyright (c) 2016 Lenovo Group
 * All Rights Reserved.
 * 
 * Project Name:event-recorder
 * Create Time: 2016年4月13日 下午5:09:00
 */
package com.lenovo.lmrp.server.eventrecorder.mock;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.lenovo.lmrp.api.model.view.EngineerRankingVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lenovo.lmrp.api.eventrecorder.ITicketStatisticsQuery;
import com.lenovo.lmrp.api.model.RestResponse;
import com.lenovo.lmrp.api.model.entity.CitygpsPO;
import com.lenovo.lmrp.api.model.view.MapStatisticsVO;
import com.lenovo.sdc.framework.annotation.RestService;
import com.lenovo.sdc.framework.dao.ADaoFactory;
import com.lenovo.sdc.framework.dao.ICommonDAO;
import com.lenovo.sdc.framework.dao.RecordFilter;
import com.lenovo.sdc.framework.util.exception.ErrorCode;
import com.lenovo.sdc.framework.util.exception.TraceableException;

/**
 * @author zhangzheng
 *
 */
@RestService
@Path("/event/v1")
@Consumes("application/json;charset-utf-8")
@Produces("application/json;charset-utf-8")
public class TicketStatisticsQueryImpl implements ITicketStatisticsQuery {
    
    private static final Logger logger = LoggerFactory.getLogger(TicketStatisticsQueryImpl.class);
    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.eventrecorder.ITicketStatisticsQuery#getCityList(java.lang.String)
     */
    @Override
    public RestResponse<List<CitygpsPO>> getCityList(String itsmcode) {
        try (ICommonDAO dao = ADaoFactory.getDefault().createDAO(itsmcode)) {
            List<CitygpsPO> cities = dao.filteByCondition(CitygpsPO.class, new RecordFilter());
            return new RestResponse<List<CitygpsPO>>(0, "ok", cities);
        }
        catch (Exception exp) {
            TraceableException.writeLog(ErrorCode.DB_QUERY_FAILED, "failed query city list.", exp);
            return new RestResponse<List<CitygpsPO>>(1, "failed", null);
        }
    }

    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.eventrecorder.ITicketStatisticsQuery#statisticsByAll(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public RestResponse<List<MapStatisticsVO>> statisticsByAll(String itsmcode, int statisticstype, Map<String, String> fields) {
        // TODO Auto-generated method stub
        logger.debug("query parameters : itsmcode {},statisticstype {},project {}",itsmcode,statisticstype,fields.get("project"));

        List<MapStatisticsVO> result = new ArrayList<>();
        MapStatisticsVO bj = new MapStatisticsVO();
        bj.setCount(100);
        Map<String, Object> point = new HashMap<>();
        point.put("lng", 116.395645);
        point.put("lat", 39.929986);
        bj.setPoint(point);
        bj.setName("北京市");
        result.add(bj);
        
        MapStatisticsVO sh = new MapStatisticsVO();
        sh.setCount(232);
        point.put("lng", 121.487899);
        point.put("lat", 31.249162);
        bj.setPoint(point);
        sh.setName("上海市");
        result.add(sh);
        
        MapStatisticsVO gz = new MapStatisticsVO();
        gz.setCount(89);
        point.put("lng", 113.30765);
        point.put("lat", 23.120049);
        bj.setPoint(point);
        gz.setName("广州市");
        result.add(gz);
        
        return new RestResponse<List<MapStatisticsVO>>(0, "ok", result);
    }

    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.eventrecorder.ITicketStatisticsQuery#statisticsByCity(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public RestResponse<List<MapStatisticsVO>> statisticsByCity(String itsmcode,Map<String, String> fields) {
        // TODO Auto-generated method stub
        logger.debug("query parameters : itsmcode {},fields {}",itsmcode,fields);
        
        List<MapStatisticsVO> result = new ArrayList<>();
        MapStatisticsVO sjz = new MapStatisticsVO();
        sjz.setCount(100);
//        sjz.setLongitude(114.522082);
//        sjz.setLatitude(39.6736218744);
        sjz.setName("石家庄市某某大街xxxxxx");
        result.add(sjz);
        
        MapStatisticsVO tj = new MapStatisticsVO();
        tj.setCount(232);
//        tj.setLongitude(117.210813);
//        tj.setLatitude(39.14393);
        tj.setName("天津市某某小区ssssssssss");
        result.add(tj);
        
        MapStatisticsVO qd = new MapStatisticsVO();
        qd.setCount(89);
//        qd.setLongitude(120.384428);
//        qd.setLatitude(36.105215);
        qd.setName("青岛市某某街道aaaaaaa");
        result.add(qd);
        
        return new RestResponse<List<MapStatisticsVO>>(0, "ok", result);
    }

    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.eventrecorder.ITicketStatisticsQuery#statisticsByRegion(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public RestResponse<List<MapStatisticsVO>> statisticsByRegion(String itsmcode, Map<String, String> fields) {
        // TODO Auto-generated method stub
        logger.debug("query parameters : itsmcode {},fields {}",itsmcode,fields);
        List<MapStatisticsVO> result = new ArrayList<>();
        MapStatisticsVO sjz = new MapStatisticsVO();
        sjz.setCount(100);
//        sjz.setLongitude(118.103886);
//        sjz.setLatitude(24.489231);
        sjz.setName("厦门某某大街xxxxxx");
        result.add(sjz);
        
        MapStatisticsVO tj = new MapStatisticsVO();
        tj.setCount(232);
//        tj.setLongitude(117.676205);
//        tj.setLatitude(24.517065);
        tj.setName("漳州某某小区ssssssssss");
        result.add(tj);
        
        MapStatisticsVO qd = new MapStatisticsVO();
        qd.setCount(89);
//        qd.setLongitude(120.384428);
//        qd.setLatitude(36.105215);
        qd.setName("青岛市某某街道aaaaaaa");
        result.add(qd);
        
        return new RestResponse<List<MapStatisticsVO>>(0, "ok", null);
    }

    @Override
    public RestResponse<List<EngineerRankingVO>> engineerRankingByEvaluate(String itsmcode, String engineerid, Map<String, String> fields) {
        return null;
    }

}
